package org.example.io;

import org.example.io.pojo.User;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class TestObjectOutputStream {

    public static void main(String[] args) throws Exception{
        //创建序列化输出流
        ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream("D:\\tmp\\user.txt"));
        //创建user对象
        User user=new User();
        user.setUsername("2222222287as");
        user.setPassword("GXJASXQSQS.xq");
        user.setAge(18);
        //写入数据
        stream.writeObject(user);
        //关闭流
        stream.close();
    }
}
